﻿Public Class LabContactViewModel
    Inherits ViewModelBase

#Region " Declarations "

    Private _cmdNewCommand As ICommand
    Private _cmdSaveCommand As ICommand
    Private _objLabContact As LabContact
    Private _strMyName As String

#End Region

#Region " Properties "

    Public Property LabContact() As LabContact
        Get
            Return _objLabContact
        End Get
        Set(ByVal Value As LabContact)
            _objLabContact = Value
            OnPropertyChanged("LabContact")
        End Set
    End Property

#End Region

#Region " Command Properties "

    Public ReadOnly Property NewCommand() As ICommand
        Get
            If _cmdNewCommand Is Nothing Then
                _cmdNewCommand = New RelayCommand(AddressOf NewExecute)
            End If
            Return _cmdNewCommand
        End Get
    End Property


    Public ReadOnly Property SaveCommand() As ICommand
        Get
            If _cmdSaveCommand Is Nothing Then
                _cmdSaveCommand = New RelayCommand(AddressOf SaveExecute, AddressOf CanSaveExecute)
            End If
            Return _cmdSaveCommand
        End Get
    End Property

#End Region

#Region " Constructors "

    Public Sub New()

    End Sub

#End Region

#Region " Command Methods "

    Private Function CanSaveExecute(ByVal param As Object) As Boolean
        Return MyBase.UIValidationErrorCount = 0 _
                AndAlso Me.LabContact.Errors.Count = 0
    End Function

    Private Sub NewExecute(ByVal param As Object)
        'in a real appplication we would perform other checks
        'before clearing the form
        Me.LabContact = New LabContact

    End Sub

    Private Sub SaveExecute(ByVal param As Object)
        'In a real applicaiton implement saving the LabContact to the database
        'In M-V-VM applications the ViewModel does not raise UI Message Boxes.
        '  Instead, a Logger Service is used.

        If Me.CanSaveExecute(Nothing) Then
            MessageBox.Show("Saved")
        End If
    End Sub

#End Region


End Class
